package com.nikkerball.apps.darkhorse.model.core;

import com.nikkerball.apps.darkhorse.model.base.TouchableObject;
import com.nikkerball.apps.darkhorse.model.change.ChangeValue;
import com.nikkerball.apps.darkhorse.model.evaluation.EvaluationPeriod;
import com.nikkerball.apps.darkhorse.model.security.User;
import org.hibernate.annotations.Cascade;

import javax.persistence.*;
import java.util.List;

import static org.hibernate.annotations.CascadeType.*;

/**
 * Represents a Year for a Classroom - contains a list to all the learners
 *
 * @author marius (created on 2010-11-24)
 */

@Entity
@Table(name = "ClassYear")
public class ClassYear extends TouchableObject {

    // ----- instance fields -----

    private Classroom classroom;

    private List<EvaluationPeriod> evaluationPeriods;

    private List<Learner> learners;

    private List<Subject> subjects;

    private List<Topic> topics;

    private List<User> users;

    private int year;

    // ----- constructors -----

    public ClassYear() {
        super();
    }

    @Transient
    public List<ChangeValue> getChangeValues() {

        return null;
    }

    public ClassYear(Classroom classroom, int year) {
        this.classroom = classroom;
        this.year = year;
    }

    // ----- public methods -----

    @ManyToOne
    @JoinColumn(name = "classroom_Id", nullable = false)
    public Classroom getClassroom() {
        return this.classroom;
    }

    public void setClassroom(Classroom classroom) {
        this.classroom = classroom;
    }

    @OneToMany(mappedBy = "classYear")
    @Cascade({MERGE, PERSIST, SAVE_UPDATE, DETACH, DELETE})
    public List<EvaluationPeriod> getEvaluationPeriods() {
        return this.evaluationPeriods;
    }

    public void setEvaluationPeriods(List<EvaluationPeriod> evaluationPeriods) {
        this.evaluationPeriods = evaluationPeriods;
    }

    @ManyToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE})
    @JoinTable(name = "ClassYear_Learner", joinColumns = @JoinColumn(name = "ClassYearId"),
            inverseJoinColumns = @JoinColumn(name = "LearnerId"))
    public List<Learner> getLearners() {
        return this.learners;
    }

    public void setLearners(List<Learner> learners) {
        this.learners = learners;
    }

    @ManyToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE})
    @JoinTable(name = "ClassYear_Subject", joinColumns = @JoinColumn(name = "ClassYearId"),
            inverseJoinColumns = @JoinColumn(name = "SubjectId"))
    public List<Subject> getSubjects() {
        return this.subjects;
    }

    public void setSubjects(List<Subject> subjects) {
        this.subjects = subjects;
    }

    @ManyToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE})
    @JoinTable(name = "ClassYear_Topic", joinColumns = @JoinColumn(name = "ClassYearId"),
            inverseJoinColumns = @JoinColumn(name = "TopicId"))
    public List<Topic> getTopics() {
        return this.topics;
    }

    public void setTopics(List<Topic> topics) {
        this.topics = topics;
    }

    @ManyToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE})
    @JoinTable(name = "ClassYear_User", joinColumns = @JoinColumn(name = "ClassYearId"),
            inverseJoinColumns = @JoinColumn(name = "UserId"))
    public List<User> getUsers() {
        return this.users;
    }

    public void setUsers(List<User> users) {
        this.users = users;
    }

    @Column(nullable = false)
    public int getYear() {
        return this.year;
    }

    public void setYear(int year) {
        this.year = year;
    }


}
